package com.CityHunter.Activity;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

import com.CityHunter.R;
import com.CityHunter.Handler.Http_Handler;
import com.CityHunter.MapActivity.Mapview;
import com.CityHunter.R.id;
import com.CityHunter.R.layout;

public class GroupView extends Activity {
	ListView listView;
	private String[] group;
	private Http_Handler http;
	private ArrayList<HashMap<String, Object>> groups = new ArrayList<HashMap<String, Object>>();
	private SharedPreferences sp;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.groupview);
		
		sp = getSharedPreferences("cityhunter", 0);
		http = new Http_Handler();

		try {
			groups = http.getGorupList(sp.getString("email", ""));
		} catch (Exception e) {
			Toast.makeText(this, e.toString(), Toast.LENGTH_LONG).show();
		}

		SimpleAdapter saImageItems = new SimpleAdapter(this, groups,
				R.layout.groupview_item, new String[] { "name", "status" },
				new int[] { R.id.name, R.id.status });

		listView = ((ListView) findViewById(R.id.group));
		listView.setAdapter(saImageItems);

		listView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				Intent intent = new Intent(GroupView.this, Mapview.class);
				intent.putExtra("grouptitle", (CharSequence) groups.get(arg2).get("name"));
				startActivityForResult(intent, 1); 
			}
		});

	}
}